<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@include file="/context/mytags.jsp" %>
<t:base type="jquery,easyui,tools,DatePicker"></t:base>
<script type="text/javascript" src="plug-in/Highcharts-4.2.4/highcharts.js"></script>
<script type="text/javascript">

    /*院线服务状态 table表格*/
    function getStatusTableData() {
        $.ajax({
            url: "cbsServiceController.do?getStatusTableData",
            cache: false,
            async: false,//必须是同步进行，为了获取 初始化 highcharts 数据
            dataType: 'json',
            type: 'POST',
            success: function (data) {
                if (data.success) {
                    clearStatusTableData(); //每次初始化表格时清空临时储存的highchart数据
                    /*----------------表格-------------------*/
                    var obj = data.obj;

                    /*故障待处理数量*/
                    var gn = obj.gnum;
                    /*备件在途数量*/
                    var bn = obj.bnum;
                    /*正常放映数*/
                    var zn = obj.znums;
                    /*现场处理中数量*/
                    var xn = obj.xnum;
//                     setclearStatusTableData("正常放映数", zn);
                    setclearStatusTableData("故障待处理数量", gn);
                    setclearStatusTableData("备件在途数量", bn);
                    setclearStatusTableData("现场处理中数量", xn);
                    /*------------------end 表格------------------*/
                } else {
                    tip(data.msg);
                }
            }
        });
    }

    var serviceLineData = [];

    function setclearStatusTableData(name, data) {
        var dt = {};
        dt.name = name;
        dt.data = [data];
        serviceLineData.push(dt);
    }

    function clearStatusTableData() {
        serviceLineData = [];
    }

    function getclearStatusTableData() {
        return serviceLineData;
    }


    /*-----------------堆叠条形图-------------------*/
    function containerHighCharts() {
        $('#container').highcharts({
            credits: {//去水印
                text: '',
                href: ''
            },
            chart: {
                type: 'bar'
            },
            title: {
                text: '服务单实时数量图',
                style: {
                    'font-family': ['Arial Negreta', 'Arial'],
                    'font-weight': '700',
                    'font-style': 'normal',
                    'font-size': '18px'
                }
            },
            xAxis: {
                categories: ['']
            },
            yAxis: {
                allowDecimals: false,
                min: 0,
                title: {
                    text: ''
                }
            },
            legend: {
                reversed: true
            },
            plotOptions: {
                series: {
                    stacking: 'normal',
                }
            },
            tooltip: {
                formatter: function () {
                    return this.series.name + '<br/><b>' + this.y + '</b>';
                },
            },
            series: getclearStatusTableData()
        });
    };

    $(function () {
        if ('true' == '${hasView}') {
            initallHighCharts();
            $("#esIpChart").hide();
            if ('true' == '${barHasView}') { //客服运营经理单独显示
                initallCharts();
            }else{
                $("#highchart").hide();
            }
        } else {
            $("#highchartContainer").hide();
            $("#esIpChart").hide();
            $("#hr_line").hide();
            $("#highchart").hide();
        }
        if ('true' == '${hasEsIpView}') {
            initallEsIpChart();
        }
        if ('true' == '${containerView}') {
            getStatusTableData();
            containerHighCharts();
        }
        if ('false' == '${containerView}') {
            $("#container").hide();
        }
        queryPageData();
        queryPageServiceData();
    });

    /************** 柱状图 ***********/
    function initallCharts() {
        Highcharts.chart('highchart', {
            credits: {//去水印
                text: '',
                href: ''
            },
            chart: {
                type: 'column'
            },
            title: {
                text: ''
            },
            xAxis: {
                categories: {
                    dataLabels: {
                        enabled: true,
                        format: '{point.name}'
                    }
                }
            },
            yAxis: {
                title: {
                    text: '本年度巡检进度'
                }
            },
            legend: {
                enabled: false
            },
            plotOptions: {
                series: {
                    dataLabels: {
                        enabled: true,
                        format: '数量：<b>{point.y}</b><br/>'
                    }
                },
                line: {
                    allowPointSelect: true,
                    cursor: 'pointer',
                    size: 160,
                    dataLabels: {
                        enabled: false,
                        formatter: function () {
                            if (this.percentage > 0) return this.point.name + '：' + this.point.y ;
                        },
                        color: 'black',
                        style: {
                            font: '13px Trebuchet MS, Verdana, sans-serif'
                        }
                    },
                    showInLegend: true
                }
            },
            series: (function () {
                var data;
                $.ajax({
                    url: 'loginController.do?getCurrYearInspectionsHighChartData&type=1',
                    async: false,
                    cache: false,
                    dataType: 'json',
                    success: function (result) {
                        data = result;
                    }
                });
                return data;
            })()
        });
    }

    function initallHighCharts() {
        /*-----------------饼图-------------------*/
        $("#highchartContainer").highcharts({
            credits: {//去水印
                text: '',
                href: ''
            },
            chart: {
                plotBackgroundColor: null,
                plotBorderWidth: null,
                plotShadow: false
            },
            legend: {
                layout: 'vertical',
                align: 'right',
                verticalAlign: 'middle',
                x: 10,
                y: 20,
                borderWidth: 0,
                labelFormatter: function () {
                    return this.name + '<br/>&nbsp';
                },
                useHTML: true
            },
            title: {
                text: '本年度巡检进度',
                style: {
                    'font-family': ['Arial Negreta', 'Arial'],
                    'font-weight': '700',
                    'font-style': 'normal',
                    'font-size': '18px'
                },
                x: -100
            },
            tooltip: {
                pointFormat: '数量：<b>{point.y}</b><br/>占比: <b>{point.percentage:.1f}%</b>'
            },
            plotOptions: {
                pie: {
                    allowPointSelect: true,
                    cursor: 'pointer',
                    size: 160,
                    dataLabels: {
                        enabled: true,
                        formatter: function () {
                            if (this.percentage > 0) return this.point.name + '：' + this.point.y + '<br/>占比：' + Highcharts.numberFormat(this.point.percentage, 1) + '%';
                        },
                        color: 'black',
                        style: {
                            font: '13px Trebuchet MS, Verdana, sans-serif'
                        }
                    },
                    showInLegend: true
                }
            },
            series: (function () {
                var data;
                $.ajax({
                    url: 'loginController.do?getCurrYearInspectionsHighChartData',
                    async: false,
                    cache: false,
                    dataType: 'json',
                    success: function (result) {
                        data = result;
                    }
                });
                return data;
            })()
        });
        /*-----------------end 饼图------------------*/
    }

    function initallEsIpChart() {
        /*-----------------堆叠柱状图-------------------*/
        $('#esIpChart').highcharts({
            credits: {//去水印
                text: '',
                href: ''
            },
            chart: {
                type: 'column'
            },
            title: {
                text: '巡检情况图表',
                style: {
                    'font-family': ['Arial Negreta', 'Arial'],
                    'font-weight': '700',
                    'font-style': 'normal',
                    'font-size': '18px'
                }
            },
            xAxis: {
                categories: ['']
            },
            yAxis: {
                allowDecimals: false,
                min: 0,
                title: {
                    text: '数量'
                },
                labels: {
                    formatter: function () {
                        return this.value + '台';
                    }
                }
            },
            tooltip: {
                formatter: function () {
                    return this.series.name + ': ' + this.y + '<br/>';
                }
            },
            plotOptions: {
                column: {
                    stacking: 'normal'
                },
                series: {
                    pointWidth: 60 //柱子之间的距离值
                }
            },
            series: (function () {
                var data;
                $.ajax({
                    url: 'cbsEsPlanIpController.do?queryHomePageEsIpHighchartData',
                    async: false,
                    cache: false,
                    dataType: 'json',
                    success: function (result) {
                        data = result;
                    }
                });
                return data;
            })()
        });
        /*-----------------end 堆叠柱状图------------------*/
    }

    function queryPageData() {
        $.ajax({
            url: "loginController.do?queryHomePageData",
            async: false,
            cache: false,
            dataType: 'json',
            type: 'POST',
            success: function (data) {
                if (data.success) {
                    var todoRoles = data.obj.todoRoles;
                    var remindRoles = data.obj.remindRoles;
                    var map = data.attributes;
                    var todoHtml = '', remindHtml = '', hadHtml = false, remind_hadHtml = false;
                    $(todoRoles).each(function (i, item) {
                        var type = "", title = item, count = 0, liHtml = "";
                        //待办事项
                        if (item == 'bsd_ipTodo') {
                            type = "bsd_ipTodo";
                            count = map.bsd_ipTodo;
                            liHtml = "个巡检计划未派单";
                            title = "待分配巡检计划";
                        } else if (item == 'bsd_ipChange') {
                            type = "bsd_ipChange";
                            count = map.bsd_ipChange;
                            liHtml = "个巡检设备变更申请待审批";
                            title = "巡检设备变更申请";
                        } else if (item == 'th_ipTodo') {
                            type = "th_ipTodo";
                            count = map.th_ipTodo;
                            liHtml = "个巡检计划未派单";
                            title = "负责人分派工程师";
                        } else if (item == 'tae_ipHadSend') {
                            type = "tae_ipHadSend";
                            count = map.tae_ipHadSend;
                            liHtml = "个巡检计划未派单";
                            title = "区域工程师分派巡检计划";
                        } else if (item == 'th_ipChange') {
                            type = "th_ipChange";
                            count = map.th_ipChange;
                            liHtml = "个巡检设备变更待审批";
                            title = "巡检设备变更申请";
                        } else if (item == 'te_ipTodo') {
                            type = "te_ipTodo";
                            count = map.te_ipTodo;
                            liHtml = "个巡检任务未接单";
                            title = "巡检任务";
                        } else if (item == 'te_ipDidnotComplete') {
                            type = "te_ipDidnotComplete";
                            count = map.te_ipDidnotComplete;
                            liHtml = "个巡检任务未完成";
                            title = "巡检任务";
                        } else if (item == 'te_ipChange') {
                            type = "te_ipChange";
                            count = map.te_ipChange;
                            liHtml = "个巡检设备变更待审批";
                            title = "巡检设备变更申请";
                        } else if (item == 'hd_wxIpServerTodo') {
                            type = "hd_wxIpServerTodo";
                            count = map.hd_wxIpServerTodo;
                            liHtml = "个未处理巡检服务申请";
                            //title = "巡检设备变更申请";
                        } else if (item == 'csa_wxBindUserTodo') {
                            type = "csa_wxBindUserTodo";
                            count = map.csa_wxBindUserTodo;
                            liHtml = "个未审核的微信认证会员申请";
                            //title = "巡检设备变更申请";
                        } else if (item == 'hdCsa_wxProcurementTodo') {
                            type = "hdCsa_wxProcurementTodo";
                            count = map.hdCsa_wxProcurementTodo;
                            liHtml = "个未处理的采购单";
                            //title = "巡检设备变更申请";
                        }

                        //{te_ipTomorrow=0, te_ipDidnotComplete=0, te_ipChange=0, te_ipTodo=1, te_ipOverTime=0}
                        if (count == 0 || item == 'hd_wxIpServerTodo' || item == 'csa_wxBindUserTodo' || item == 'hdCsa_wxProcurementTodo') {//
                            todoHtml += '<li>' + count + liHtml + '</li>';
                            hadHtml = true;
                        } else {
                            todoHtml += '<li><a href="javacript:void(0)" onclick="goViewIp(\'' + type + '\',\'' + title + '\')">' + count + '</a>&nbsp;' + liHtml + '</li>';
                            hadHtml = true;
                        }
                    });
                    if (hadHtml) {
                        $("#taskDiv").append('<div class="home_task" style="background-color:#FFFFCC;"><label>巡检待办</label><ul>' + todoHtml + '</ul></div>');
                    }
                    $(remindRoles).each(function (i, item) {
                        //任务提醒
                        var remind_type = "", remind_title = item, remind_count = 0, remind_liHtml = "";
                        if (item == 'th_ipOverTime') {
                            remind_type = "th_ipOverTime";
                            remind_count = map.th_ipOverTime;
                            remind_liHtml = "个巡检计划超时";
                            remind_title = "巡检任务";
                        } else if (item == 'te_ipOverTime') {
                            remind_type = "te_ipOverTime";
                            remind_count = map.te_ipOverTime;
                            remind_liHtml = "个巡检任务超时";
                            remind_title = "巡检任务";
                        } else if (item == 'te_ipTomorrow') {
                            remind_type = "te_ipTomorrow";
                            remind_count = map.te_ipTomorrow;
                            remind_liHtml = "个巡检计划即将到期，请于明日上门巡检";
                            remind_title = "巡检任务";
                        } else if (item == 'hd_ipHadNoIeOverTime') {
                            remind_type = "hd_ipHadNoIeOverTime";
                            remind_count = map.hd_ipHadNoIeOverTime;
                            remind_liHtml = "个巡检服务未评价";
                            remind_title = "巡检评价";
                        }

                        if (remind_count == 0) {
                            remindHtml += '<li>' + remind_count + remind_liHtml + '</li>';
                            remind_hadHtml = true;
                        } else {
                            remindHtml += '<li><a href="javacript:void(0)" onclick="goViewIp(\'' + remind_type + '\',\'' + remind_title + '\')">' + remind_count + '</a>&nbsp;' + remind_liHtml + '</li>';
                            remind_hadHtml = true;
                        }
                    });
                    if (remind_hadHtml) {
                        $("#taskDiv").append('<div class="home_task" style="background-color:#FFE8DD;"><label>任务提醒</label><ul>' + remindHtml + '</ul></div>');
                    }
                } else {
                    tip(data.msg);
                }
            }
        });
    }

    /*
    * 首页代办服务单数量
    * */
    function queryPageServiceData() {
        $.ajax({
            url: "loginController.do?queryHomePageServiceData",
            async: false,
            cache: false,
            dataType: 'json',
            type: 'POST',
            success: function (data) {
                if (data.success) {
                    var todoRoles = data.obj.todoRoles;
                    var remindRoles = data.obj.remindRoles;
                    var map = data.attributes;
                    var todoHtml = '', remindHtml = '', hadHtml = false, remind_hadHtml = false;
                    $(todoRoles).each(function (i, item) {
                        var type = "", title = item, count = 0, liHtml = "";
                        //待办事项
                        if (item == 'qy_enginerTodoArea') {
                            type = "qy_enginerTodoArea";
                            count = map.qy_enginerTodoArea;
                            liHtml = "个服务单待处理(区域工程师任务)";
                            title = "区域工程师待办任务";
                        } else if (item == 'qy_enginerTodoMy') {
                            type = "qy_enginerTodoMy";
                            count = map.qy_enginerTodoMy;
                            liHtml = "个服务单待处理(我的任务)";
                            title = "我的任务待办";
                        } else if (item == 'enginerTodo') {
                            type = "enginerTodo";
                            count = map.enginerTodo;
                            liHtml = "个服务单待处理";
                            title = "我的任务待办";
                        } else if (item == 'enginerReturnTodo') {
                            type = "enginerReturnTodo";
                            count = map.enginerReturnTodo;
                            liHtml = "个返件待处理";
                            title = "待返件任务";
                        } else if (item == 'swTodo') {
                            type = "swTodo";
                            count = map.swTodo;
                            liHtml = "个服务单待处理";
                            title = "服务商商务待办任务";
                        } else if (item == 'wlTodo') {
                            type = "wlTodo";
                            count = map.wlTodo;
                            liHtml = "个发货单待发货";
                            title = "发货管理待办列表";
                        } else if (item == 'wlYfhTodo') {
                            type = "wlYfhTodo";
                            count = map.wlYfhTodo;
                            liHtml = "个发货单待签收";
                            title = "发货管理待办列表";
                        } else if (item == 'wlReturnTodo') {
                            type = "wlReturnTodo";
                            count = map.wlReturnTodo;
                            liHtml = "个返件待处理";
                            title = "物流返件待办列表";
                        } else if (item == 'csaTodo') {
                            type = "csaTodo";
                            count = map.csaTodo;
                            liHtml = "个服务单待处理";
                            title = "CSA服务单管理待办列表";
                        } else if (item == 'csaDelinerTodo') {
                            type = "csaDelinerTodo";
                            count = map.csaDelinerTodo;
                            liHtml = "个发货单待处理";
                            title = "CSA发货单待办列表";
                        } else if (item == 'csaReturnTodo') {
                            type = "csaReturnTodo";
                            count = map.csaReturnTodo;
                            liHtml = "个返件待处理";
                            title = "CSA返件待办列表";
                        } else if (item == 'bakeTodo') {
                            type = "bakeTodo";
                            count = map.bakeTodo;
                            liHtml = "个服务单待处理";
                            title = "服务单管理待办列表";
                        } else if (item = 'barcoCSManager') {
                            type = "bakeTodo";
                            count = map.bakeTodo;
                            liHtml = "个服务单待处理";
                            title = "服务单管理待办列表";
                        }

                        if (count == 0) {//
                            todoHtml += '<li>' + count + liHtml + '</li>';
                            if (item == 'barcoCSManager') {/*巴克客服部运营经理*/
                                hadHtml = false;
                            } else {
                                hadHtml = true;
                            }
                        } else {
                            todoHtml += '<li><a href="javacript:void(0)" style="font-size: large" onclick="goView(\'' + type + '\',\'' + title + '\')">' + count + '</a>&nbsp;' + liHtml + '</li>';
                            if (item == 'barcoCSManager') {/*巴克客服部运营经理*/
                                hadHtml = false;
                            } else {
                                hadHtml = true;
                            }

                        }
                    });
                    if (hadHtml) {
                        $("#myDiv").append('<div class="home_task" style="background-color:#FFFFCC;"><label>服务单待办</label><ul>' + todoHtml + '</ul></div>');
                    } else {
                        $("#barco").append('<div class="home_task" style="background-color:#FFFFCC;width: 98%;margin-bottom: 20px"><label>服务单待办</label><ul>' + todoHtml + '</ul></div>');
                    }
                } else {
                    tip(data.msg);
                }
            }
        });
    }

    function goViewIp(type, title) {
        addOneTab(title, "zyInspectionPlanController.do?viewPlanInHomePage&type=" + type);
    }

    /*
    * 去我的任务列表
    * */
    function goView(type, title) {
        if (title == '区域工程师待办任务') {
            addOneTab(title, "cbsServiceAssignListController.do?argEngineerlistTodo&type=" + type);
        }
        if (title == '我的任务待办') {
            addOneTab(title, "cbsServiceAssignListController.do?engineerlistsTodo&type=" + type);
        }
        if (title == '服务商商务待办任务') {
            addOneTab(title, "cbsServiceAssignListController.do?facilitatorlistTodo&type=" + type);
        }
        if (title == '发货管理待办列表') {
            addOneTab(title, "cbsDelinerController.do?cbsDelinerTodo&type=" + type);
        }
        if (title == '物流返件待办列表') {
            addOneTab(title, "cbsReturnEquipmentController.do?cbsReturnEquipmentWLTodo&type=" + type);
        }
        if (title == 'CSA服务单管理待办列表') {
            addOneTab(title, "cbsServiceController.do?cbsServiceFoodorCSATodo&type=" + type);
        }
        if (title == 'CSA发货单待办列表') {
            addOneTab(title, "cbsDelinerController.do?cbsCSADelinerTodo&type=" + type);
        }
        if (title == 'CSA返件待办列表') {
            addOneTab(title, "cbsReturnEquipmentController.do?cbsReturnEquipmentCSATodo&type=" + type);
        }
        if (title == '待返件任务') {
            addOneTab(title, "cbsReturnEquipmentController.do?cbsReturnEquipmentGCSTodo&type=" + type);
        }
        if (title == '服务单管理待办列表') {
            addOneTab(title, "cbsServiceController.do?cbsServiceFoodorBaKeTodo&type=" + type);
        }
    }
</script>
<%--<div style="margin-top: 14px;">--%>
<%--<h3>简介</h3>--%>
<%--中影巴可客户服务系统--%>
<%--</div>--%>
<div id="barco"></div> <%--单独巴克客服运营经理显示的内容--%>
<div id="container" style="width:33%;height:350px;display: inline-block;"></div>
<div id="highchartContainer"
     style="width:33%;height: 350px;display: inline-block;border-left: 1px solid #CCCCCC;"></div>
<div id="highchart" style="width:63%;height: 350px;display: inline-block;border-left: 1px solid #CCCCCC;"></div>
<div id="esIpChart" style="width:33%;height: 350px;display: inline-block;border-left: 1px solid #CCCCCC;"></div>
<hr id="hr_line" style="background-color: #CCCCCC; height: 1px; border: none;"/>
<div id="taskDiv">
</div>
<div id="myDiv">
</div>
